package com.csun.cmny.provider.job.simple;

import com.csun.cmny.provider.model.dto.SendClockDto;
import com.csun.cmny.provider.service.DmcRpcService;
import com.csun.cmny.provider.service.OpcRpcService;
import com.csun.cmny.util.DateUtil;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.paascloud.elastic.lite.annotation.ElasticJobConfig;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-10-28 17:52
 * @Description:
 */
@Slf4j
//@ElasticJobConfig(cron = "0 0/1 * * * ?")
public class SendAppClockMessageJob implements SimpleJob {

    @Resource
    private OpcRpcService opcRpcService;
    @Resource
    private DmcRpcService dmcRpcService;

    /**
     * Execute.
     *
     * @param shardingContext the sharding context
     */
    @Override
    public void execute(final ShardingContext shardingContext) {

        Date date = new Date();

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);

        // 获取周期
        int w = cal.get(Calendar.DAY_OF_WEEK) - 2;
        if (w == -1) {
            w = 6;
        }

        String str = DateUtil.YYYY_MM_DD_MM_HH_SS.format(date);
        String time = str.substring(11, 16);

        log.info("定时推送APP闹钟 ==》 {}, 周数 = {}， 时间 = {}", DateUtil.dateToString(date), w, time);

        SendClockDto sendClockDto = new SendClockDto();
        sendClockDto.setIndex(w);
        sendClockDto.setTime(time);

        // opcRpcService.sendAppClockMsg(sendClockDto);
    }


}
